package jfuzzyprincepless.zarchive.negotiation.protocols.utilityfuncprotocol;

import jfuzzyprincepless.zarchive.algorithm.structure.ICommandConstruction;
import jfuzzyprincepless.zarchive.negotiation.protocols.INegotiationProtocol__Q_del;
import jfuzzyprincepless.negotiation.INegotiation;
import jfuzzyprincepless.negotiation.INegotiationContext;

public class UtilityFunctionBasedProtocol
	implements INegotiationProtocol__Q_del
{
	private INegotiationProtocol__Q_del subProtocol;
	private int negotiateLimit;

	public UtilityFunctionBasedProtocol(
		INegotiationProtocol__Q_del subProtocol,
		int negotiateLimit
	) {
		this.subProtocol = subProtocol;
		this.negotiateLimit = negotiateLimit;
	}

	public UtilityFunctionBasedProtocol(
		INegotiationProtocol__Q_del subProtocol
	) {
		this(subProtocol, -1);
	}

	@Override
	public INegotiation createNegotiation(
		ICommandConstruction construction,
		INegotiationContext context
	) {
		INegotiation subnegotiation =
			subProtocol.createNegotiation(construction, context);
		UtilityFuncNegotiation negotiation =
			new UtilityFuncNegotiation(subnegotiation);
		if (negotiateLimit > 0) {
			negotiation.setNegotiateLimit(negotiateLimit);
		}
		return negotiation;
	}
}
